package com.mcy.springbatch.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.annotation.AfterChunk;
import org.springframework.batch.core.annotation.BeforeChunk;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.stereotype.Component;

/**
 * chunk的监听器，使用注解的方式实现
 * 实现StepExecutionListener接口也可以
 */
@Slf4j
@Component
public class StepListener {

    @BeforeChunk
    public void beforeChunk(ChunkContext context){
        log.info("Step执行之前监听:{}",context.getStepContext().getStepName());
    }

    @AfterChunk
    public void afterChunk(ChunkContext context){
        log.info("Step执行之后监听:{}",context.getStepContext().getStepName());
    }
}
